<template>
    <div>
        <div class="top_box container_box">
            <p class="page-title font-weight-500">开课推送

            </p>
        </div>
        <div class="padding_box">
            <div class="container_box">
                <div class="order_title">
                    开课推送
                </div>
                <el-divider></el-divider>
                <el-form :model="pushData"
                         label-width="120px">
                    <el-form-item label="课程"
                                  class="aa">
                        <el-autocomplete clearable
                                         v-model="curriculumEle2"
                                         popper-class="my-autocomplete"
                                         :debounce="500"
                                         :trigger-on-focus="false"
                                         :fetch-suggestions="querySearchAsync2"
                                         placeholder="请输入课程名搜索"
                                         @select="handleSelectCurriculumId2">
                        </el-autocomplete>
                    </el-form-item>
                    <el-form-item style="width:100%"
                                  label="备注">
                        <el-input type="textarea"
                                  :rows="4"
                                  placeholder="请输入备注"
                                  v-model="pushData.remake">
                        </el-input>
                    </el-form-item>
                    <el-form-item style="width:100%"
                                  label="">
                        <el-button type="primary"
                                   @click="pushDataFun">推送</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import axios from '@/utils/axios.js';
import businessCard from '@/components/business-card/business-card.vue';
import { Loading } from 'element-ui';

export default {
    name: 'basetable',
    components: {
        businessCard
    },
    data() {
        return {
            // 上传加载遮罩
            loaddingTip: {
                text: "正在上传,请稍等",
                background: "rgba(0, 0, 0, 0.7)"
            },
            pushData: {},
            curriculumEle2: '',
            userInfo: JSON.parse(sessionStorage.getItem('userInfo'))
        };
    },
    watch: {
        curriculumEle2(newV) {
            if (newV.length == 0) {
                this.pushData = {}
            }
        },
    },
    filters: {
    },
    created() {
        this.custimerQrcode = this.userInfo.customerService
        this.$forceUpdate()
    },
    methods: {
        pushDataFun() {
            axios({
                url: "/admin/user/startClassMessage",
                method: "post",
                data: this.pushData
            }).then((res) => {
                if (res.code == 0) {
                    this.$message.success('推送成功')
                } else {
                    this.$message.error('推送失败')
                }
            }).catch(err => {
                this.$message.error('推送失败')
            })
        },
        querySearchAsync2(queryString, cb) {
            if (queryString.length > 0) {
                let data = {
                    keyword: queryString
                }
                axios({
                    url: "/admin/classSchedule/searchClassSchedule",
                    method: "post",
                    data
                }).then(res => {
                    let arr = []
                    if (res.code == 0 && res.data) {
                        if (res.data && res.data.length > 0) {
                            res.data.forEach(ele => {
                                arr.push({
                                    // 课表id
                                    id: ele.id,
                                    // 课程id
                                    productId: ele.productResp.id,
                                    productName: ele.productResp.name,
                                    schoolTimeStr: ele.schoolTimeStr && ele.schoolTimeStr.join(','),
                                    schoolAddress: ele.schoolAddress,
                                    weekStr: ele.weekStr && ele.weekStr.join(','),
                                    value: ele.weekStr.join(',') + '>' + ele.productResp.name
                                })
                            });
                            cb(arr);
                        } else {
                            let arr = [{ value: '无匹配数据' }]
                            cb(arr);
                        }
                    }
                })
            }
        },
        // 点击查询数据
        handleSelectCurriculumId2(item) {
            this.pushData.addrStr = item.schoolAddress
            this.pushData.classStr = item.productName
            this.pushData.timeStr = item.schoolTimeStr
            console.log('>>>>>>>>>>>>>>>>>', item)
        },
    }
};
</script>

<style lang="scss" scoped >
</style>
<style lang="scss" scoped>
</style>
